package com.qiguliuxing.dts.admin.web;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
import com.qiguliuxing.dts.admin.dao.*;
import com.qiguliuxing.dts.admin.dao.dto.EditPageQuery1;
import com.qiguliuxing.dts.admin.dao.dto.EditPageQuery2;
import com.qiguliuxing.dts.admin.dao.dto.OrderPageQuery;
import com.qiguliuxing.dts.admin.dao.dto.SplitListQuery;
import com.qiguliuxing.dts.admin.listener.IordersTemplateListener;
import com.qiguliuxing.dts.admin.service.AdminDailyOrderService;
import com.qiguliuxing.dts.admin.service.AdminIorderService;
import com.qiguliuxing.dts.admin.service.AdminIorderStockService;
import com.qiguliuxing.dts.admin.util.AuthSupport;
import com.qiguliuxing.dts.admin.util.excel.core.StringUtils;
import com.qiguliuxing.dts.core.util.ResponseUtil;
import com.qiguliuxing.dts.db.dao.domain.ProductCountTemplate;
import com.qiguliuxing.dts.db.domain.DailyOrder;
import com.qiguliuxing.dts.db.domain.IoralStock;
import com.qiguliuxing.dts.db.domain.Iorders;
import com.qiguliuxing.dts.db.domain.ProductProduction;
import com.qiguliuxing.dts.db.service.IoralStockService;
import com.qiguliuxing.dts.db.service.ProductProductionService;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.*;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

@RestController
@RequestMapping("/admin/iorder")
@Validated
public class AdminIordersController {

    @Autowired
    private AdminIorderService adminIorderService;
    @Autowired
    private ProductProductionService productProductionService;
    @Autowired
    private AdminIorderStockService adminIorderStockService;
    @Autowired
    private IoralStockService ioralStockService;

    @Autowired
    private AdminDailyOrderService adminDailyOrderService;
    private static final Logger logger = LoggerFactory.getLogger(AdminIordersController.class);

    @RequiresPermissions("admin:iorders:list")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日分装统计"}, button = "查找")
    @PostMapping("/list")
    public Object list(@RequestBody OrderPageQuery orderPageQuery /*@RequestParam(defaultValue = "2024-01-01") String startTime, @RequestParam(defaultValue = "2024-12-31") String endTime, String batchNumber, @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,String[] startToEnd

                       */) {
        /*logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘订单->查询,请求参数:instrumentNumber:{},instrumentName:{},page:{}",startToEnd.toString());*/
        //需要区分数据权限，如果属于品牌商管理员，则需要获取当前用户管理品牌店铺
        /*   List<Integer> brandIds = null;*//*
         *//*if (adminDataAuthService.isBrandManager()) {*//*
         *//*        brandIds = adminDataAuthService.getBrandIds();
            logger.info("运营商管理角色操作，需控制数据权限，brandIds:{}",JSONObject.toJSONString(brandIds));

            if (brandIds == null || brandIds.size() == 0) {
                Map<String, Object> data = new HashMap<>();
                data.put("total", 0L);
                data.put("items", null);

                logger.info("【请求结束】商品管理->商品管理->查询,响应结果:{}", JSONObject.toJSONString(data));
                return ResponseUtil.ok(data);
          *//**//*  }*//*
         *//*     }*/
      /*  String startTime="";
        String endTime="";
        String[] ste=orderPageQuery.getStartToEnd().toArray(new String[0]);
        String batchNumber=orderPageQuery.getBatchNumber();
        Integer page=1;
        Integer limit=10;*/
        String startTime = "";
        String endTime = "";
        List<String> ste = new ArrayList<>();
        ste = orderPageQuery.getStartToEnd();
        if (ste != null && !ste.isEmpty()) {
            startTime = ste.get(0).substring(0, 10);
            endTime = ste.get(1).substring(0, 10);
            logger.info(ste.toString());
            logger.info(startTime + endTime);
        }
        String sort=orderPageQuery.getSort();
        String order=orderPageQuery.getOrder();


        return adminIorderService.list(startTime, endTime, orderPageQuery.getBatchNumber(), orderPageQuery.getPage(), orderPageQuery.getLimit(),sort,order/*, sort,order*/);
    }


    @GetMapping("/listByDate")
    public Object listByDate(/*@RequestBody OrderPageQuery orderPageQuery*/List<String> dates) {

        List<DailyOrder> listDailyOrders = new ArrayList<>();

        dates.stream().forEach(object -> {
            List<DailyOrder> listDailyOrder = new ArrayList<>();
            listDailyOrder = AdminIorderService.selectOrderByDate(object);
            logger.info(object);
        });
        Map<String, Object> data = new HashMap<>();


        return ResponseUtil.ok(data);
    }

/*    @GetMapping("/catAndBrand")
    public Object catAndBrand() {
        return adminInstrumentService.catAndBrand();
    }*/

    /**
     * 编辑商品
     *
     * @param iordersAll
     * @return
     */
    @RequiresPermissions("admin:iorders:update")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "编辑")
    @PostMapping("/update")
    public Object update(@RequestBody IordersAll iordersAll) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘131生产发货管理->订单列表->编辑,请求参数:{}", JSONObject.toJSONString(iordersAll));

        return adminIorderService.update(iordersAll);
    }


    /* @RequiresPermissions("admin:iorders:update")*/
    /*    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "编辑")*/
    @PostMapping("/getStock")
    public Object getStock(@RequestParam(defaultValue = "2024-01-01") String useTime, @RequestParam Integer pieces, String splitQuantity, String actualOrderCount, String selectedItem) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘131生产发货管理->订单列表->编辑,请求参数:{}", JSONObject.toJSONString(selectedItem));
        logger.info(splitQuantity);
        String[] stockInfo = selectedItem.split("/");
        String useTime1 = "";
        Integer id = 0;
        String batchNumber1 = "";
        String volume1 = "0.00";
        Integer pieces1 = 0;
        Integer stockId1 = 0;
        String orderCount1 = "0.00";
        LocalDateTime measureTime1 = null;
        LocalDate productionDate1 = null;
        Double actualCount1 = 0.00;
        batchNumber1 = selectedItem.substring(0, 10);
        for (String s : stockInfo) {
            if (s.contains("使用时间")) {
                useTime1 = s.replaceFirst(".*：", "");
            } else if (s.contains("件数")) {
                pieces1 = Integer.parseInt(s.replaceFirst(".*：", ""));
            } else if (s.contains("订量")) {
                orderCount1 = s.replaceFirst(".*：", "");
                orderCount1=orderCount1.substring(0,orderCount1.indexOf("m"));
            } else if (s.contains("分装体积")) {
                volume1 = s.replaceFirst(".*：", "");
                volume1=volume1.substring(0,volume1.indexOf("m"));
            } else if (s.contains("id")) {
                id = Integer.parseInt(s.replaceFirst(".*：", ""));
            }
        }
        logger.info("今天");
        logger.info(selectedItem);
        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber1);
        measureTime1 = production.getMeasureTine();
        productionDate1 = production.getProductionDate();
        IoralStock ioralStock = ioralStockService.findById(id);
        stockId1 = ioralStock.getId();
        actualCount1 = ioralStock.getActivity();
        Map<String, Object> data = new HashMap<>();
        data.put("measureTime1", measureTime1);
        data.put("productionDate1", productionDate1);
        data.put("actualCount1", actualCount1);
        data.put("orderCount1", orderCount1);
        data.put("volume1", volume1);
        data.put("stockId1", stockId1);
        data.put("batchNumber1", batchNumber1);
        if (pieces < pieces1) {
            data.put("pieces1", pieces);
        } else {
            data.put("pieces1", pieces1);
        }
        logger.info(data.toString());
        return ResponseUtil.ok(data);
    }

    /**
     * 编辑商品
     *
     * @param
     * @return
     */
    @RequiresPermissions("admin:iorders:calcAll")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "汇总")
    @PostMapping("/calcAll")
    public Object addToTotal(@RequestBody List<IordersTemplate> iordersTemplates) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘131生产发货管理->订单列表->编辑,请求参数:{}", JSONObject.toJSONString(iordersTemplates));

        List<ProductCountTemplate> productCountTemplates = new ArrayList<>();
        ProductCountTemplate productCountTemplate = new ProductCountTemplate();
        String batchNumber = "";
        String productionDate = "";
        double totalV = 0;
        double totalC = 0;
        double constantNum = -0.0864089775561;

        double orderCountVolume = 0.00;
        double orderTotalActivity = 0.00;
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {

            }
        }
        return productCountTemplates;
    }


    @RequiresPermissions("admin:iorders:queryProduction")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "查看分装统计")
    @PostMapping("/queryProduction")
    public Object queryProductCount(@RequestBody List<IordersTemplate> iordersTemplates) {
        List<ProductCountTemplate> productCountTemplates = new ArrayList<>();
        ProductCountTemplate productCountTemplate = new ProductCountTemplate();
        String batchNumber = "";
        String productionDate = "";
        double totalV = 0;
        double totalC = 0;
        double constantNum = -0.0864089775561;
         logger.info("测试");
        double orderCountVolume = 0.00;
        double orderTotalActivity = 0.00;
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {
                batchNumber = it.getMaterialBatch();
                orderCountVolume = orderCountVolume + Double.valueOf(it.getSplitQuantity()) * it.getPieces();
                orderTotalActivity = orderTotalActivity + Double.valueOf(it.getActualCount())* it.getPieces();
                /*productionDate=it.getDate();*/
            }
        }
        double activity = 0;
        double reVolume = 0;
        ProductProduction productProduction = productProductionService.queryByBatchNumber(batchNumber);
        totalC = productProduction.getProductActivity();
        totalV = productProduction.getProductCapacity();
        productionDate = String.valueOf(productProduction.getProductionDate());
        if (productProduction.getRemainingCapacity() != null && productProduction.getRemainingActivity() != null && productProduction.getRemainingActivity() > 0) {
            activity = productProduction.getRemainingActivity();
            reVolume = productProduction.getRemainingCapacity();
        } else {
            activity = 0.00;
            reVolume = 0.00;
        }
        /* double result =activity * Math.exp(constantNum * (ChronoUnit.DAYS.between(productProduction.getMeasureTine(), LocalDate.now())));*/
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        productCountTemplate.setOrderCountVolume(Double.valueOf(decimalFormat.format(orderCountVolume)));
        productCountTemplate.setRemainingVolume(Double.valueOf(decimalFormat.format(reVolume)));
        productCountTemplate.setRemainingActivity(Double.valueOf(decimalFormat.format(activity)));
        productCountTemplate.setProductionDate(productionDate);
        productCountTemplate.setOrderTotalActivity(Double.valueOf(decimalFormat.format(orderTotalActivity / 1000)));
        productCountTemplate.setOrderCountVolume(Double.valueOf(decimalFormat.format(orderCountVolume)));
        productCountTemplate.setTotalC(totalC);
        productCountTemplate.setTotalV(totalV);
        productCountTemplates.add(productCountTemplate);
        Map<String, Object> data = new HashMap<>();
        data.put("items", productCountTemplates);
        logger.info("测试推送到新分支");
        logger.info("测试推送到新分支");
        /*data.put("batchNumber",batchNumber);
        data.put("orderCountActivity",orderTotalActivity);
        data.put("orderCountVolume",orderCountVolume);*/

        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        logger.info("查询产品分装总量/总活度等信息成功");
        return ResponseUtil.ok(data);
    }

    //查询合格证信息
    @RequiresPermissions("admin:iorders:queryCF")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "查看合格证")
    @PostMapping("/queryCF")
    public Object queryCf(@RequestBody List<IordersTemplate> iordersTemplates) {
        List<CF> cfs = new ArrayList<>();
        CF cf = new CF();
        Integer cf121 = 0;
        Integer cf120 = 0;
        Integer cf119 = 0;
        Integer cf122 = 0;
        Integer orderCount = 0;
        Integer cfTotal = 0;

        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {
                orderCount = Integer.valueOf(it.getOrderCount());
                if (orderCount < 50) {
                    cf122 = cf122 + 1;
                } else if (orderCount >= 50 && orderCount < 100) {
                    cf119 = cf119 + it.getPieces();
                } else if (orderCount >= 100 && orderCount < 200) {
                    cf120 = cf120 + it.getPieces();
                } else if (orderCount >= 200) {
                    cf121 = cf121 + it.getPieces();
                } else {

                }
            }
        }
        cfTotal = cf119 + cf120 + cf121 + cf122;
        cf.setCf120(cf120);
        cf.setCf119(cf119);
        cf.setCf121(cf121);
        cf.setCf122(cf122);
        cf.setCfTotal(cfTotal);
        cfs.add(cf);
        Map<String, Object> data = new HashMap<>();
        data.put("items", cfs);

        /*data.put("batchNumber",batchNumber);
        data.put("orderCountActivity",orderTotalActivity);
        data.put("orderCountVolume",orderCountVolume);*/

        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);
    }

    //判断某些医院用铁C还是铁B。
    public String insureDeliveryType(String userName, Double orderCount) {
        String deliveryType = "";
        boolean a = userName == "广西北海市第二人民医院" && orderCount < 200;
        boolean b = userName == "山西省肿瘤医院" && orderCount < 200;
        boolean c = userName == "宾阳县宾州城中医院有限公司" && orderCount < 200;
        boolean d = userName == "广西合浦县人民医院" && orderCount < 200;
        boolean e = userName == "河池市第三人民医院" && orderCount < 200;
        boolean f = userName == "横县中医医院" && orderCount < 200;
        boolean g = userName == "灵山县人民医院" && orderCount < 200;
        boolean h = userName == "广西壮族自治区民族医院" && orderCount < 200;
        boolean i = userName == "平南县中医医院" && orderCount < 200;
        boolean j = userName == "钦州市第二人民医院" && orderCount < 200;
        boolean k = userName == "广西医科大学附属武鸣医院" && orderCount < 200;
        boolean l = userName == "甘肃省武威肿瘤医院" && orderCount < 200;
        boolean m = userName == "河北医科大学第四医院" && orderCount < 200;
        if (a || b || c || d || e || f || g || h || i || j || k || l || m) {
            deliveryType = "铁B";
        } else {
            deliveryType = "铁C";
        }
        return deliveryType;
    }

    public void packOrderToList(ArrayList<IorderSplit> iorderSplits, String deliveryType, Double orderCount) {
        if (deliveryType == "铁B") {
            if (orderCount >= 50 && orderCount < 100) {

            }
        } else if (deliveryType == "铁C") {

        } else {

        }

    }


    @RequiresPermissions("admin:iorders:insertMany")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "确认上传")
    @PostMapping("/addTestIorders")
    public Object addDailyIorders(@RequestBody List<IordersTemplate> iordersTemplates) {
        boolean a = false;
        Double totalActivity = 0.00;
        Double totalVolume = 0.00;
        ProductProduction productProduction = null;
        IordersAll iordersAll2 = new IordersAll();
        Iorders iorder = IorderSpecial.getIorders(iordersTemplates);

        iordersAll2.setIorders(iorder);
        adminIorderService.create(iordersAll2);
        if (iordersTemplates != null) {
            for(IordersTemplate iordersTemplate:iordersTemplates){
                productProduction=productProductionService.queryByBatchNumber(iordersTemplate.getMaterialBatch());
                break;
            }
        }
        if (productProduction.getRemainingActivity()-iorder.getSplitActivity() > 0 && productProduction.getRemainingCapacity()-iorder.getSplitVolume() > 0) {
        /*double constantNum = -0.0864089775561;*/
              DecimalFormat decimalFormat = new DecimalFormat("#0.00");
              DecimalFormat decimalFormat2 = new DecimalFormat("YYYY-MM-dd HH:mm:ss ");
              if (iordersTemplates != null) {
                  for (IordersTemplate it : iordersTemplates) {
                      /*if(it.getMaterialBatch()!=productProduction.getBatchNumber()){
                          continue;
                      }*/
                      IordersAll iordersAll = new IordersAll();
                      DailyOrder dailyOrder = new DailyOrder();
                      String selectedItem = it.getSelectedItem();
                      Integer stockId = it.getStockId();


                     if (it.getStockId() != null) {
                          IoralStock iorderStock = ioralStockService.findById(stockId);
                          if (it.getPieces() == iorderStock.getPieces()) {
                              adminIorderStockService.delete(iorderStock);
                          } else {
                        iorderStock.setPieces(iorderStock.getPieces()-it.getPieces());
                        iorderStock.setEditPieces(iorderStock.getPieces());
                        ioralStockService.updateById(iorderStock);

                    }
                    logger.info("已使用备货：产品批号：" + iorderStock.getBatchNumber() + "//体积：" + iorderStock.getVolume() + "//件数：" + it.getPieces());
                }

                productProduction = productProductionService.queryByBatchNumber(it.getMaterialBatch());
                BeanUtils.copyProperties(it, dailyOrder);
                dailyOrder.setShowId(it.getShowId());
                dailyOrder.setSplitQuantity(it.getSplitQuantity());
                /*DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd");*/
                /*LocalDateTime localDateTime = LocalDateTime.parse(it.getUseTime());*/
                /* String ust=it.getUseTime().substring(0,9);*/
                if (it.getUseTime().length() > 12) {

                    dailyOrder.setUseTime(LocalDateTime.parse(it.getUseTime()));
                } else {
                    dailyOrder.setUseTime(LocalDate.parse(it.getUseTime()).atTime(12, 0));

                }
                dailyOrder.setDate(LocalDate.parse(it.getDate()));
                dailyOrder.setActualCount(it.getActualCount());
                dailyOrder.setPieces(it.getPieces());
                dailyOrder.setConsigneeTelephone(it.getConsigneeTelephone());
                dailyOrder.setArrivalStation(it.getArrivalStation());
                dailyOrder.setConsignee(it.getConsignee());
                dailyOrder.setNotes(it.getNotes());

                dailyOrder.setDeliveryType(it.getDeliveryType());
                dailyOrder.setDate(LocalDate.now());
                logger.info(it.getShowId() + " : " + it.getCustomerName());
                dailyOrder.setOrderCount(it.getOrderCount());
                dailyOrder.setCustomerName(it.getCustomerName());
                dailyOrder.setActualCount(it.getActualCount());
                iorder.setBatchNumber(dailyOrder.getMaterialBatch());
                totalActivity=totalActivity+Double.valueOf(it.getActualCount())/1000;
                totalVolume=totalVolume+Double.valueOf(it.getSplitQuantity());
                /*iorder.setRemainActivity(productProduction.getProductActivity());
                iorder.setRemainVolume(productProduction.getRemainingCapacity());*/
                /*iordersAll.setIorders(iorder);*/
                iordersAll.setDailyOrder(dailyOrder);
                /*iordersAll.setIorders(iorder);*/
                iordersAll2 = iordersAll;

                adminDailyOrderService.create(iordersAll);
            }
        }
            productProduction.setRemainingActivity(productProduction.getRemainingActivity() - totalActivity);
            productProduction.setRemainingCapacity(productProduction.getRemainingCapacity() - totalVolume);

            iorder.setRemainActivity(productProduction.getRemainingActivity());//产品剩余活度
            iorder.setRemainVolume(productProduction.getRemainingCapacity());//产品剩余体积
            iorder.setProductionActivity(productProduction.getProductActivity());//产品总活度
            iorder.setProductionQuantity(productProduction.getProductCapacity());//产品总体积
            iorder.setConcentration(Double.valueOf(productProduction.getOralConcentration()));//浓度
            iorder.setDate(LocalDate.now().toString());
            iordersAll2.setIorders(iorder);
            adminIorderService.create(iordersAll2);
            productProductionService.updateById(productProduction);
            logger.info("【请求结束】碘订单->订单管理->上传订单至数据库,响应结果:{}", "成功!");
            long total = PageInfo.of(iordersTemplates).getTotal();
            Map<String, Object> data = new HashMap<>();
            data.put("total", total);
            data.put("items", iordersTemplates);
            logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
            return ResponseUtil.ok(data);
        } else {
           /* Map<String, Object> data = new HashMap<>();
            long total = PageInfo.of(iordersTemplates).getTotal();
            data.put("total", total);
            data.put("items", iordersTemplates);*/
            return ResponseUtil.fail();
        }

    }


    /**
     * 删除器材
     *
     * @param iorders
     * @return
     */
    @RequiresPermissions("admin:iorders:delete")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody Iorders iorders) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘订单管理->删除,请求参数:{}", JSONObject.toJSONString(iorders));
        logger.info("cxc");
        return adminIorderService.delete(iorders);
    }


    /**
     * 生成备货
     *
     * @param
     * @return
     */
    @RequiresPermissions("admin:iorders:createStock")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "查看备货")
    @PostMapping("/createStock")
    public Object createStockUp(@RequestBody List<IordersTemplate> iordersTemplates) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘订单管理->生成备货,请求参数:{}", JSONObject.toJSONString("iorders"));
        logger.info("生成备货");
        List<IoralStock> ioralStocks = new ArrayList<>();
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {
                IoralStock ioralStock = new IoralStock();
                Integer showId = it.getShowId();
                ioralStock.setShowId(showId);
                // 获取当前时间
                ioralStock.setUserName("备货");
                LocalDateTime now = LocalDate.now().atTime(12, 0);

                // 创建一个代表4天的Period对象
                Period fourDays = Period.ofDays(4);

                // 在当前时间基础上添加4天
                LocalDateTime fourDaysLater = now.plus(fourDays);
                ioralStock.setOrderCount(Integer.parseInt(it.getOrderCount()));
                ioralStock.setUseTime(fourDaysLater);
                ioralStock.setDeliveryType("空运");
                ioralStock.setPieces(it.getPieces());
                ioralStock.setBatchNumber(it.getMaterialBatch());
                ioralStock.setVolume(it.getSplitQuantity());
                ioralStocks.add(ioralStock);
                ioralStock.setActivity(Double.valueOf(it.getActualCount()));
                IordersAll iordersAll = new IordersAll();
                iordersAll.setIoralStock(ioralStock);
                adminIorderService.create(iordersAll);
            }
        }
        long total = PageInfo.of(ioralStocks).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", ioralStocks);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));

        return ResponseUtil.ok(data);
    }


    /**
     * @param
     * @return
     */
    @RequiresPermissions("admin:iorders:create")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "新增")
    @GetMapping("/create")
    public Object create(@RequestBody IordersAll iordersAll) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘131生产发货管理->订单列表->新增,请求参数:{}", JSONObject.toJSONString(iordersAll));
        Iorders iorders = iordersAll.getIorders();


        logger.info(iordersAll.toString());
        return adminIorderService.create(iordersAll);
    }

    @Value("${spring.servlet.multipart.location}")
    private String uploadDir;

    //    @RequiresPermissions("admin:iorders:uploadExcels")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "上传订单")
    @PostMapping(value = "/uploadExcels")
    public List<IordersTemplate> uploadExcel(@RequestPart("file") @NotNull MultipartFile file, @RequestParam(value = "batchNumber") String batchNumber) throws IOException {
        if (file.isEmpty()) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "文件不能为空");
        }
        logger.info(batchNumber);
        /*String batchNumber= dailyOrderPageQuery.getBatchNumber();*/
        String fileName = file.getOriginalFilename();
        if (StringUtils.isBlank(fileName) || !fileName.endsWith(".xlsx")) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "仅支持上传 .xlsx 文件");
        }


        InputStream inputStream = file.getInputStream();
        IordersTemplateListener iordersTemplateListener = new IordersTemplateListener();
        EasyExcel.read(inputStream, IordersTemplate.class, iordersTemplateListener).headRowNumber(3).sheet().doRead();
        Integer pic = 0;
        /*double constantNum = -0.0864089775561;*/
        double constantNum = -0.0864089775561;
        Double x = 400.00;
        Double c = 150.00;
        Integer d1 = 3;
        Double result3 = 0.00;
        result3 = c * Math.exp(-constantNum * 3);
        /*logger.info(String.valueOf(result3));*/
        /*double totalVolume = 0; //订单总体积
        double totalActivity=0; //订单总活度*/
        List<IordersTemplate> iordersTemplates = iordersTemplateListener.getList();
        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {
                IordersAll iordersAll = new IordersAll();
                DailyOrder iorder = new DailyOrder();
                BeanUtils.copyProperties(it, iorder);
//                DateTimeFormatter formatter = new DateTimeFormatter("");
                /*iorder.setUseTime(LocalDateTime.now());
                iorder.setShowId(it.getShowId());
                iorder.setActualOrderCount(it.getActualOrderCount());
                iordersAll.setDailyOrder(iorder);*/
                /*  String batchNumber2=dailyOrderPageQuery.getBatchNumber();*/
                /*queryNewestBatch();*/
                if (production != null) {
                    // 计算出需要多少天
                    // math.exp()
                    Integer concentration = production.getOralConcentration();
                    /*double constantNum = -0.0864089775561;*/
                    double resultTest = ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(it.getUseTime()).atTime(12, 0));
                    double result = concentration * Math.exp(constantNum * ((ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(it.getUseTime()).atTime(12, 0)) + 1)));
                  /*  if(result>10){
                        pic=Integer.valueOf((int) (result/10))+1;
                        result=result/pic;
                    }*/
                    // 计算

                    DecimalFormat decimalFormat = new DecimalFormat("#0.00");
                    DecimalFormat decimalFormat2 = new DecimalFormat("#0");
                    double orderCountTest = Double.valueOf(it.getOrderCount());
                    float concentrate1 = Float.parseFloat(production.getOralConcentration().toString());// 浓度
                    double volumeTest = Double.parseDouble(it.getOrderCount()) / result;
                    double volume1 = (orderCountTest / result) * IorderSpecial.getResult(it.getCustomerName());
                    if (volume1 > 10) {
                        pic = Integer.valueOf((int) (volume1 / 10)) + 1;
                        volume1 = volume1 / pic;
                        it.setPieces(pic);
                        pic = 0;
                    } else {
                        it.setPieces(it.getPieces());
                    }
                    String concentrate = decimalFormat.format(concentrate1);
                    String volume = decimalFormat.format(volume1);
                    it.setSplitQuantity(volume + "");   //实际分装量（活度）
                    it.setCustomerName(it.getCustomerName());
                    it.setActualCount(decimalFormat2.format(Math.round(volume1 * concentration)) + "");//实际分装量
                    it.setMaterialBatch(production.getBatchNumber());
                    it.setDate(LocalDate.now().toString());
                    it.setMeasureTime(production.getMeasureTine().toString());
                    it.setProductionDate(production.getProductionDate().toString());
                    iorder.setUseTime(LocalDate.parse(it.getUseTime()).atTime(12, 0));
                    iorder.setShowId(it.getShowId());
                    iorder.setOrderNumber(it.getOrderNum());
                    iorder.setOrderRowNumber(it.getOrderLineNum());
                    iorder.setActualCount(it.getActualCount());
                    /*totalVolume= Double.parseDouble(totalVolume+it.getActualOrderCount());*/
                    iorder.setConsigneeTelephone(it.getConsigneeTelephone());
                    iorder.setArrivalStation(it.getArrivalStation());
                    iorder.setSplitQuantity(it.getSplitQuantity());
                    /*totalActivity= (Double.parseDouble(totalVolume+it.getSplitQuantity()))/1000;*/
                    iorder.setPieces(it.getPieces());
                    iorder.setMaterialBatch(production.getBatchNumber());

                }

                iordersAll.setDailyOrder(iorder);

                /*adminDailyOrderService.create(iordersAll);*/
            }
        }

        logger.info("上传成功");
        return iordersTemplates;
    }


    @RequiresPermissions("admin:iorders:getTotalSheet")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "生成总表")
    @PostMapping("/getTotalSheet")
    public Object getTotalInfo(@RequestBody List<IordersTemplate> iordersTemplates) throws IOException {
       /* Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Data");*/
        IorderInfoAll infoAll = new IorderInfoAll();
        List<IorderInfoAll.InfoAll> infoAllList = new ArrayList<>();
        IorderInfoAll.InfoAll infos = null;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        DecimalFormat decimalFormat2 = new DecimalFormat("#0.0");
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {
                infos = new IorderInfoAll.InfoAll();
                /*Integer showId=it.getShowId();*/
                infos.setShowId(it.getShowId());
                infos.setUserName(it.getCustomerName());
                infos.setUseTime(it.getUseTime());
                infos.setPieces(it.getPieces());
                infos.setOrderCount(Integer.valueOf(it.getOrderCount()));
                infos.setDeliveryType(it.getDeliveryType());
                infos.setConcentration(Integer.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getOralConcentration()));
                infos.setBatchNumber(it.getMaterialBatch());
                infos.setConsegnee(it.getConsignee());
                infos.setConsegneePhone(it.getConsigneeTelephone());
                infos.setAddress(it.getAddress());
                infos.setSplitDate(LocalDate.now().toString());
                infos.setMeasureTime(it.getMeasureTime());
                infos.setSpecs(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setOrderNumber(it.getOrderNum());
                infos.setOrderLineNumber(it.getOrderNum());
                infos.setPackageBase(decimalFormat.format(IorderSpecial.getPackIndex(Integer.parseInt(it.getOrderCount()), it.getDeliveryType(), Double.valueOf(it.getSplitQuantity()))));
                infos.setSplitBase(decimalFormat.format(Double.valueOf(it.getSplitQuantity()) / Double.valueOf(infos.getPackageBase())));
                infos.setSplitQuatity(Double.valueOf(it.getActualCount()));
                infos.setUnitPrice(ChineseMoneyConverter.getUnitPrice(Integer.valueOf(it.getOrderCount())));
                infos.setAllcac(Double.valueOf(it.getSplitQuantity()) * it.getPieces());  //总分装体积
                infos.setAvgCac(Double.valueOf(it.getSplitQuantity()));//平均每件分多少体积
                infos.setTotalPrice(ChineseMoneyConverter.CalculateMoney(Integer.valueOf(it.getOrderCount())));
                infos.setChineseYuan(new ChineseMoneyConverter2().format(infos.getTotalPrice().toString()));
                infos.setTotalCal(Double.valueOf(it.getSplitQuantity()) * it.getPieces());
                infos.setPackType(IorderSpecial.getPackType(it.getDeliveryType(), Integer.valueOf(it.getOrderCount())));
                infos.setConcentrationGbq(Double.valueOf(infos.getConcentration()) * 0.037 + "GBq");
                infos.setTransportIndex(IorderSpecial.getTransIndex(Integer.valueOf(it.getOrderCount())).toString());
                infos.setLabelCount(String.valueOf(decimalFormat2.format(Integer.valueOf(it.getOrderCount()) * 0.037)));
                infos.setPzwh(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setProductionDate(String.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getProductionDate()));
                infos.setOverdue(LocalDate.parse(infos.getProductionDate()).plusDays(24).toString());
                infos.setActPack(String.valueOf(Math.round(infos.getSplitQuatity() * infos.getPieces())));
                infos.setPackMbq(String.valueOf(Integer.valueOf(infos.getActPack()) * 37));
                infoAllList.add(infos);
            }

        }
        infoAll.setInfoAllList(infoAllList);
        String templateFilePath = "D:/1--碘－131计算程序/模版/总表.xlsx";
        String outFilePath = "D:/1--碘－131计算程序/计算结果/订单信息处理结果表.xlsx";
        // 创建 ExcelWriter 实例
        ExcelWriter excelWriter = EasyExcel
                // 写入到
                .write(outFilePath)
                // 指定模板
                .withTemplate(templateFilePath)
                .build();

        WriteSheet sheet2 = EasyExcel.writerSheet().build();
        FillConfig fillConfig = FillConfig.builder()
                // 开启填充换行
                .forceNewRow(true)
                .build();
        // 执行填充操作
        excelWriter.fill(infoAll, fillConfig, sheet2);

        excelWriter.fill(infoAll.getInfoAllList(), fillConfig, sheet2);
        // 结束
        excelWriter.finish();

        /*response.setHeader("Content-Disposition", "attachment; filename=example.xlsx");
        try (OutputStream out = response.getOutputStream()) {
            workbook.write(out);
        }*/
        long total = PageInfo.of(iordersTemplates).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("fileLocation", outFilePath);
        data.put("items", iordersTemplates);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        logger.info("SDFSDFSDF");
        return ResponseUtil.ok(data)/*adminIorderService.delete(iordersTemplates)*/;

    }


    /**
     * 器材详情
     *
     * @param id
     * @return
     */
    @RequiresPermissions("admin:iorders:read")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "详情")
    @GetMapping("/detail")
    public Object detail(@NotNull Integer id) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘订单管理->详情,请求参数,id:{}", id);
        logger.info("hehehehheheh");
        return adminIorderService.detail(id);
    }

    @RequiresPermissions("admin:iorders:read")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "详情")
    @GetMapping("/more")
    public Object detail2(@NotNull Integer id) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘订单->详情,请求参数,id:{}", id);
        logger.info("hehehehheheh");
        return adminIorderService.detail(id);
    }

    //生成分装单
    @RequiresPermissions("admin:iorders:getSplitSheet")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "每日数据汇总"}, button = "生成分装单")
    @PostMapping("/getSplitSheet")
    public Object getSplitList(@RequestBody List<IordersTemplate> iordersTemplates) throws IOException {
       /* Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Data");*/
        IorderInfoAll infoAll = new IorderInfoAll();
        List<IorderSpitSheet.Kc119> kc119List = new ArrayList<>(30);
        List<IorderSpitSheet.Kc120> kc120List = new ArrayList<>(30);
        List<IorderSpitSheet.Kc121> kc121List = new ArrayList<>(30);
        List<IorderSpitSheet.Kc122> kc122List = new ArrayList<>(30);

        List<IorderSpitSheet.Tc119> tc119List = new ArrayList<>(30);
        List<IorderSpitSheet.Tc120> tc120List = new ArrayList<>(30);
        List<IorderSpitSheet.Tc121> tc121List = new ArrayList<>(30);

        List<IorderSpitSheet.Tb119> tb119List = new ArrayList<>(30);
        List<IorderSpitSheet.Tb120> tb120List = new ArrayList<>(30);
        List<IorderSpitSheet.Tb121> tb121List = new ArrayList<>(30);

        Map<Double, Integer> mapKc121 = new HashMap<>();
        Map<Double, Integer> mapKc120 = new HashMap<>();
        Map<Double, Integer> mapKc119 = new HashMap<>();
        Map<Double, Integer> mapTc121 = new HashMap<>();
        Map<Double, Integer> mapTc120 = new HashMap<>();
        Map<Double, Integer> mapTc119 = new HashMap<>();
        Map<Double, Integer> mapTb121 = new HashMap<>();
        Map<Double, Integer> mapTb120 = new HashMap<>();
        Map<Double, Integer> mapTb119 = new HashMap<>();
        Map<Double, Integer> mapKc122 = new HashMap<>();
        IorderSpitSheet sheet = new IorderSpitSheet();
        Integer totalCount = 0;
        Integer total121Bo = 0, total120Bo = 0, total119Bo = 0, total122Bo = 0;
        String deliveryType = "";
        Double orderCount = 0.0;
        IorderInfoAll.InfoAll infos = null;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        DecimalFormat decimalFormat2 = new DecimalFormat("#0.0");
        DecimalFormat decimalFormat3 = new DecimalFormat("#0");
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {
                deliveryType = it.getDeliveryType();
                orderCount = Double.valueOf(it.getOrderCount());

                infos = new IorderInfoAll.InfoAll();
                /*Integer showId=it.getShowId();*/
                infos.setShowId(it.getShowId());
                infos.setUserName(it.getCustomerName());
                infos.setUseTime(it.getUseTime());
                infos.setPieces(it.getPieces());
                infos.setOrderCount(Integer.valueOf(it.getOrderCount()));
                infos.setDeliveryType(it.getDeliveryType());
                infos.setConcentration(Integer.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getOralConcentration()));
                infos.setBatchNumber(it.getMaterialBatch());

                infos.setConsegnee(it.getConsignee());
                infos.setConsegneePhone(it.getConsigneeTelephone());
                infos.setAddress(it.getAddress());
                infos.setSplitDate(LocalDate.now().toString());
                infos.setMeasureTime(it.getMeasureTime());
                infos.setSpecs(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setOrderNumber(it.getOrderNum());
                infos.setOrderLineNumber(it.getOrderNum());
                infos.setPackageBase(decimalFormat.format(IorderSpecial.getPackIndex(Integer.parseInt(it.getOrderCount()), it.getDeliveryType(), Double.valueOf(it.getSplitQuantity()))));
                infos.setSplitBase(decimalFormat.format(Double.valueOf(it.getSplitQuantity()) / Double.valueOf(infos.getPackageBase())));
                infos.setSplitQuatity(Double.valueOf(it.getActualCount()));
                infos.setUnitPrice(ChineseMoneyConverter.getUnitPrice(Integer.valueOf(it.getOrderCount())));
                infos.setAllcac(Double.valueOf(it.getSplitQuantity()) * it.getPieces());  //总分装体积
                infos.setAvgCac(Double.valueOf(it.getSplitQuantity()));//平均每件分多少体积
                infos.setTotalPrice(ChineseMoneyConverter.CalculateMoney(Integer.valueOf(it.getOrderCount())));
                infos.setChineseYuan(new ChineseMoneyConverter2().format(infos.getTotalPrice().toString()));
                infos.setTotalCal(Double.valueOf(it.getSplitQuantity()) * it.getPieces());
                infos.setPackType(IorderSpecial.getPackType(it.getDeliveryType(), Integer.valueOf(it.getOrderCount())));
                infos.setConcentrationGbq(Double.valueOf(infos.getConcentration()) * 0.037 + "GBq");

                infos.setLabelCount(String.valueOf(decimalFormat2.format(Integer.valueOf(it.getOrderCount()) * 0.037)));
                infos.setPzwh(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setProductionDate(String.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getProductionDate()));
                infos.setOverdue(LocalDate.parse(infos.getProductionDate()).plusDays(24).toString());
                infos.setActPack(String.valueOf(Math.round(infos.getSplitQuatity() * infos.getPieces())));
                infos.setPackMbq(String.valueOf(Integer.valueOf(infos.getActPack()) * 37));
                totalCount = totalCount + infos.getPieces();

                if ((deliveryType.equals("空运") || deliveryType.equals("汽运")) && orderCount < 50) {
                    total122Bo = total122Bo + it.getPieces();
                    if (mapKc122.containsKey(infos.getAvgCac())) {
                        mapKc122.put(infos.getAvgCac(), it.getPieces() + mapKc122.get(infos.getAvgCac()));
                    } else {
                        mapKc122.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if ((deliveryType.equals("空运") || deliveryType.equals("汽运")) && orderCount >= 50 && orderCount < 100) {
                    total119Bo = total119Bo + it.getPieces();
                    if (mapKc119.containsKey(infos.getAvgCac())) {
                        mapKc119.put(infos.getAvgCac(), it.getPieces() + mapKc119.get(infos.getAvgCac()));
                    } else {
                        mapKc119.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if ((deliveryType.equals("空运") || deliveryType.equals("汽运")) && orderCount >= 100 && orderCount < 200) {
                    total120Bo = total120Bo + it.getPieces();
                    if (mapKc120.containsKey(infos.getAvgCac())) {
                        mapKc120.put(infos.getAvgCac(), it.getPieces() + mapKc120.get(infos.getAvgCac()));
                    } else {
                        mapKc120.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if ((deliveryType.equals("空运") || deliveryType.equals("汽运")) && orderCount >= 200) {
                    total121Bo = total121Bo + it.getPieces();
                    if (mapKc121.containsKey(infos.getAvgCac())) {
                        mapKc121.put(infos.getAvgCac(), it.getPieces() + mapKc121.get(infos.getAvgCac()));
                    } else {
                        mapKc121.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if (deliveryType.equals("铁运") && orderCount >= 50 && orderCount < 100) {
                    total119Bo = total119Bo + it.getPieces();
                    if (mapTc119.containsKey(infos.getAvgCac())) {
                        mapTc119.put(infos.getAvgCac(), it.getPieces() + mapTc119.get(infos.getAvgCac()));
                    } else {
                        mapTc119.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if (deliveryType.equals("铁运") && orderCount >= 100 && orderCount < 200) {
                    total120Bo = total120Bo + it.getPieces();
                    if (mapTc120.containsKey(infos.getAvgCac())) {
                        mapTc120.put(infos.getAvgCac(), it.getPieces() + mapTc120.get(infos.getAvgCac()));
                    } else {
                        mapTc120.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if (deliveryType.equals("铁运") && orderCount >= 200) {
                    total121Bo = total121Bo + it.getPieces();
                    if (mapTc121.containsKey(infos.getAvgCac())) {
                        mapTc121.put(infos.getAvgCac(), it.getPieces() + mapTc121.get(infos.getAvgCac()));
                    } else {
                        mapTc121.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if (deliveryType.equals("铁运") && orderCount >= 50 && orderCount < 100 && it.getNotes().contains("铁大铅罐")) {
                    total119Bo = total119Bo + it.getPieces();
                    if (mapTb119.containsKey(infos.getAvgCac())) {
                        mapTb119.put(infos.getAvgCac(), it.getPieces() + mapTb119.get(infos.getAvgCac()));
                    } else {
                        mapTb119.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if (deliveryType.equals("铁运") && orderCount >= 100 && orderCount < 200 && it.getNotes().contains("铁大铅罐")) {
                    total120Bo = total120Bo + it.getPieces();
                    if (mapTb120.containsKey(infos.getAvgCac())) {
                        mapTb120.put(infos.getAvgCac(), it.getPieces() + mapTb120.get(infos.getAvgCac()));
                    } else {
                        mapTb120.put(infos.getAvgCac(), it.getPieces());
                    }
                } else if (deliveryType.equals("铁运") && orderCount >= 200 && it.getNotes().contains("铁大铅罐")) {
                    total121Bo = total121Bo + it.getPieces();
                    if (mapTb121.containsKey(infos.getAvgCac())) {
                        mapTb121.put(infos.getAvgCac(), it.getPieces() + mapTb121.get(infos.getAvgCac()));
                    } else {
                        mapTb121.put(infos.getAvgCac(), it.getPieces());
                    }
                }
                /*infoAllList.add(infos);*/
            }

        }
        sheet.setBatchNumber(infos.getBatchNumber());
        sheet.setConcentration(infos.getConcentration());
        sheet.setMeasureTime(infos.getMeasureTime());
        sheet.setProductionDate(infos.getProductionDate());
        sheet.setOverdue(infos.getOverdue());
        sheet.setTotalCounts(totalCount);
        sheet.setTotal119Bo(total119Bo);
        sheet.setTotal120Bo(total120Bo);
        sheet.setTotal121Bo(total121Bo);
        sheet.setTotal122Bo(total122Bo);
        sheet.setTotalB(totalCount + 1);
        sheet.setConcentrationGBq(decimalFormat.format(infos.getConcentration() * 0.037));
        mapKc121.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Kc121 kc121 = new IorderSpitSheet.Kc121();
            kc121.setVolumeKc121(key);
            kc121.setCountKc121("* " + value);
            kc121List.add(kc121);
            Collections.sort(kc121List, Collections.reverseOrder());
        });
        mapKc120.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Kc120 kc120 = new IorderSpitSheet.Kc120();
            kc120.setVolumeKc120(key);
            kc120.setCountKc120("* " + value);
            kc120List.add(kc120);
            Collections.sort(kc120List, Collections.reverseOrder());
        });
        mapKc119.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Kc119 kc119 = new IorderSpitSheet.Kc119();
            kc119.setVolumeKc119(key);
            kc119.setCountKc119("* " + value);
            kc119List.add(kc119);
            Collections.sort(kc119List, Collections.reverseOrder());

        });
        mapKc122.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Kc122 kc122 = new IorderSpitSheet.Kc122();
            kc122.setVolumeKc122(key);
            kc122.setCountKc122("* " + value);
            kc122List.add(kc122);
            Collections.sort(kc122List, Collections.reverseOrder());
        });
        mapTc121.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Tc121 tc121 = new IorderSpitSheet.Tc121();
            tc121.setVolumeTc121(key);
            tc121.setCountTc121("* " + value);
            tc121List.add(tc121);
            Collections.sort(tc121List, Collections.reverseOrder());

        });
        mapTc120.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Tc120 tc120 = new IorderSpitSheet.Tc120();
            tc120.setVolumeTc120(key);
            tc120.setCountTc120("* " + value);
            tc120List.add(tc120);
            Collections.sort(tc120List, Collections.reverseOrder());
        });
        mapTc119.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Tc119 tc119 = new IorderSpitSheet.Tc119();
            tc119.setVolumeTc119(key);
            tc119.setCountTc119("* " + value);
            tc119List.add(tc119);
            Collections.sort(tc119List, Collections.reverseOrder());
        });
        mapTb121.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Tb121 tb121 = new IorderSpitSheet.Tb121();
            tb121.setVolumeTb121(key);
            tb121.setCountTb121("* " + value);
            tb121List.add(tb121);
            Collections.sort(tb121List, Collections.reverseOrder());
        });
        mapTb120.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Tb120 tb120 = new IorderSpitSheet.Tb120();
            tb120.setVolumeTb120(key);
            tb120.setCountTb120("* " + value);
            tb120List.add(tb120);
            Collections.sort(tb120List, Collections.reverseOrder());
        });
        mapTb119.forEach((key, value) -> {
            // 处理key和value
            IorderSpitSheet.Tb119 tb119 = new IorderSpitSheet.Tb119();
            tb119.setVolumeTb119(key);
            tb119.setCountTb119("* " + value);
            tb119List.add(tb119);
            Collections.sort(tb119List, Collections.reverseOrder());
        });

        sheet.setListKc119(kc119List);
        sheet.setListKc120(kc120List);
        sheet.setListKc121(kc121List);
        logger.info(String.valueOf(kc121List.size()));
        sheet.setListKc122(kc122List);
        sheet.setListTc119(tc119List);
        sheet.setListTc120(tc120List);
        sheet.setListTc121(tc121List);
        sheet.setListTb119(tb119List);
        sheet.setListTb120(tb120List);
        sheet.setListTb121(tb121List);

        String templateFilePath = "D:/1--碘－131计算程序/模版/分装单模板.xlsx";
        String outFilePath = "D:/1--碘－131计算程序/计算结果/分装单.xlsx";
        // 创建 ExcelWriter 实例
        /*FileInputStream fileInputStream = new FileInputStream(new File(templateFilePath));
        Workbook workbook = new XSSFWorkbook(fileInputStream);*/
       /* try (FileInputStream fileInputStream = new FileInputStream(new File(templateFilePath));
             Workbook workbook = new XSSFWorkbook(fileInputStream)) {

            Sheet sheetx = workbook.getSheetAt(0); // 获取第一个Sheet
            for (Row row : sheetx) { // 迭代每一行
                if(row.getRowNum()==10) {
                    Cell cell = row.getCell(8);
                    cell.setCellValue("werwerwerwerwerwerwer");
                    logger.info(sheetx.getSheetName());
                    logger.info(cell.getStringCellValue());
                }*/
                /*if(row.getRowNum()==15) {

                    for (Cell cell : row) { // 迭代每一列
                        // 根据不同的数据类型，以不同的方式读取数据
                        if(cell.getColumnIndex()==4 || cell.getColumnIndex()==8) {
                            cell.setCellValue("吵你🐎");
                        }
                    }
                }*/
         /*       System.out.println(); // 换行
            }
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        try (ExcelWriter excelWriter = EasyExcel.write(outFilePath).registerWriteHandler(new WriteOnlyValueHandler()).withTemplate(templateFilePath).build()) {

            WriteSheet sheet2 = EasyExcel.writerSheet().build();
            /*FillConfig fillConfig = FillConfig.builder()
                    // 开启填充换行
                    .forceNewRow(true)
                    .build();
*/
            excelWriter.fill(sheet.getListKc119(), sheet2);
            excelWriter.fill(sheet.getListKc120(), sheet2);
            excelWriter.fill(sheet.getListKc121(), sheet2);
            excelWriter.fill(sheet.getListTc119(), sheet2);
            excelWriter.fill(sheet.getListTc120(), sheet2);
            excelWriter.fill(sheet.getListTc121(), sheet2);
            excelWriter.fill(sheet.getListKc122(), sheet2);
            excelWriter.fill(sheet.getListTb119(), sheet2);
            excelWriter.fill(sheet.getListTb120(), sheet2);
            excelWriter.fill(sheet.getListTb121(), sheet2);
            excelWriter.fill(sheet, sheet2);
            logger.info(sheet.getBatchNumber());
            /*excelWriter.fill(sheet.getBatchNumber(),sheet2);*/
            // 结束
            excelWriter.finish();
        } catch (Exception e) {
            e.printStackTrace();
            logger.info(e.toString());
        }

        // 执行填充操作


        /*response.setHeader("Content-Disposition", "attachment; filename=example.xlsx");
        try (OutputStream out = response.getOutputStream()) {
            workbook.write(out);
        }*/
        long total = PageInfo.of(iordersTemplates).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("fileLocation", outFilePath);
        data.put("items", iordersTemplates);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        logger.info("SDFSDFSDF");
        return ResponseUtil.ok(data)/*adminIorderService.delete(iordersTemplates)*/;

    }


    //生产发运记录
    @RequiresPermissions("admin:iorders:getShipAccord")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "生成发运记录")
    @PostMapping("/getShipAccord")
    public Object getShippingAccord(@RequestBody List<IordersTemplate> iordersTemplates) throws IOException {
       /* Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Data");*/
        IorderInfoAll infoAll = new IorderInfoAll();

        List<IorderInfoAll.InfoAll> infoAllList = new ArrayList<>();
        Integer totalCount = 0;
        Integer totalAc = 0;
        Integer totalPieces = 0;
        String deliveryType = "";
        Double orderCount = 0.0;
        IorderInfoAll.InfoAll infos = null;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        DecimalFormat decimalFormat2 = new DecimalFormat("#0.0");
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {

                infos = new IorderInfoAll.InfoAll();
                /*Integer showId=it.getShowId();*/
                infos.setShowId(it.getShowId());
                infos.setUserName(it.getCustomerName());
                infos.setUseTime(it.getUseTime());
                totalPieces = totalPieces + it.getPieces();
                infos.setPieces(it.getPieces());
                totalCount = totalCount + Integer.valueOf(it.getOrderCount());
                infos.setOrderCount(Integer.valueOf(it.getOrderCount()));
                infos.setDeliveryType(it.getDeliveryType());
                infos.setConcentration(Integer.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getOralConcentration()));
                infos.setBatchNumber(it.getMaterialBatch());
                infos.setConsegnee(it.getConsignee());
                infos.setConsegneePhone(it.getConsigneeTelephone());
                infos.setAddress(it.getAddress());
                infos.setProductName("碘[131I]化钠口服溶液");
                infos.setDateTime(LocalDate.now().toString());
                infos.setSplitDate(LocalDate.now().toString());
                infos.setMeasureTime(it.getMeasureTime());
                infos.setSpecs(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setOrderNumber(it.getOrderNum());
                infos.setOrderLineNumber(it.getOrderNum());
                infos.setPackageBase(decimalFormat.format(IorderSpecial.getPackIndex(Integer.parseInt(it.getOrderCount()), it.getDeliveryType(), Double.valueOf(it.getSplitQuantity()))));
                infos.setSplitBase(decimalFormat.format(Double.valueOf(it.getSplitQuantity()) / Double.valueOf(infos.getPackageBase())));
                infos.setSplitQuatity(Double.valueOf(it.getActualCount()));
                infos.setUnitPrice(ChineseMoneyConverter.getUnitPrice(Integer.valueOf(it.getOrderCount())));
                infos.setAllcac(Double.valueOf(it.getSplitQuantity()) * it.getPieces());  //总分装体积
                infos.setAvgCac(Double.valueOf(it.getSplitQuantity()));//平均每件分多少体积
                infos.setTotalPrice(ChineseMoneyConverter.CalculateMoney(Integer.valueOf(it.getOrderCount())));
                infos.setChineseYuan(new ChineseMoneyConverter2().format(infos.getTotalPrice().toString()));
                infos.setTotalCal(Double.valueOf(it.getSplitQuantity()) * it.getPieces());
                infos.setPackType(IorderSpecial.getPackType(it.getDeliveryType(), Integer.valueOf(it.getOrderCount())));
                infos.setConcentrationGbq(Double.valueOf(infos.getConcentration()) * 0.037 + "GBq");

                infos.setLabelCount(String.valueOf(decimalFormat2.format(Integer.valueOf(it.getOrderCount()) * 0.037)));
                infos.setPzwh(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setProductionDate(String.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getProductionDate()));
                infos.setOverdue(LocalDate.parse(infos.getProductionDate()).plusDays(24).toString());
                infos.setActPack(String.valueOf(Math.round(infos.getSplitQuatity() * infos.getPieces())));
                infos.setPackMbq(String.valueOf(Integer.valueOf(infos.getActPack()) * 37));
                infoAllList.add(infos);
            }

        }


        infoAll.setInfoAllList(infoAllList);
        infoAll.setTotalActivity(totalCount);
        infoAll.setTotalPiece(totalPieces);
        infoAll.setDateNow(LocalDate.now().toString());
        String templateFilePath = "D:/1--碘－131计算程序/模版/发运记录模板.xlsx";
        String outFilePath = "D:/1--碘－131计算程序/计算结果/中间件/发运记录目标.xlsx";

        // 创建 ExcelWriter 实例
        ExcelWriter excelWriter = EasyExcel
                // 写入到
                .write(outFilePath)
                // 指定模板
                .withTemplate(templateFilePath)
                .build();

        WriteSheet sheet2 = EasyExcel.writerSheet().build();
        /*FillConfig fillConfig = FillConfig.builder()
                // 开启填充换行
                .forceNewRow(true)
                .build();*/
        // 执行填充操作
        excelWriter.fill(infoAll.getInfoAllList(), /*fillConfig, */sheet2);
        excelWriter.fill(infoAll, /*fillConfig, */sheet2);
       /* WriteSheet writeSheet = EasyExcel.writerSheet().build();
        for (int i = 1; i <= 3; i++) {
            writeSheet.getCopier().deleteRow(i);
        }*/

        // 结束
        excelWriter.finish();
        String outFilePath1 = IorderSpecial.createShipAccordFile();

        try (FileInputStream fis = new FileInputStream(outFilePath);
             Workbook workbook = new XSSFWorkbook(fis);
             FileOutputStream fos = new FileOutputStream(outFilePath1)) {
            XSSFFont font = (XSSFFont) workbook.createFont();
            font.setFontName("宋体");
            font.setFontHeightInPoints((short) 9); // 设置字体大小为12点

            // 创建单元格样式并应用字体
            XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle();
            style.setFont(font);
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setBorderTop(BorderStyle.THIN);
            style.setBorderBottom(BorderStyle.THIN);
            style.setBorderLeft(BorderStyle.THIN);
            style.setBorderRight(BorderStyle.THIN);
            Sheet sheet = workbook.getSheetAt(0); // 获取工作表
            int startRow = iordersTemplates.size() + 5;
            int endRow = iordersTemplates.size() + 7;
            /*for(int n=7;n<=9+iordersTemplates.size();n++){
                Row row = sheet.getRow(n);
                Cell cellN = row.createCell(14);
                cellN.setCellStyle(style);
                cellN.setCellValue("/"); // 设置单元格的值
            }*/

          /*  for (int rowNum = startRow; rowNum <= endRow; rowNum++) {
                Row row = sheet.getRow(rowNum); // 创建行对象
                for(int j=1;j<14;j++){
                    Cell cell = row.createCell(j); // 创建单元格对象
                    cell.setCellStyle(style);
                    cell.setCellValue("/"); // 设置单元格的值
                }

            }*/

            Row row1 = sheet.getRow(iordersTemplates.size() + 4);
            for (int j = 0; j < 13; j++) {
                Cell cell = row1.createCell(j);
                cell.setCellStyle(style);
                cell.setCellValue("/");
            }
            Row row2 = sheet.getRow(iordersTemplates.size() + 6); // 获取行，如果行不存在则返回null，需要创建行
            for (int k = 0; k < 13; k++) {
                Cell cell = row2.createCell(k);
                cell.setCellStyle(style);
            }
            /*Row row3 = sheet.getRow(iordersTemplates.size()+9);*/
            /* if (row == null) {
                row = sheet.createRow(rowIndex); // 创建行
            }*/
            Cell cell1 = row1.createCell(5); // 获取单元格，如果单元格不存在则返回null，需要创建单元格
            cell1.setCellStyle(style);
            cell1.setCellValue(totalCount);
            Cell cell2 = row1.createCell(7);
            cell2.setCellStyle(style);
            cell2.setCellValue(totalPieces);
            Cell cell3 = row2.createCell(1);
            cell3.setCellValue("计划：黄宏");
            cell3.setCellStyle(style);
            Cell cell4 = row2.createCell(4);
            cell4.setCellStyle(style);
            cell4.setCellValue("生产：薛广东");
            Cell cell5 = row2.createCell(7);
            cell5.setCellStyle(style);
            cell5.setCellValue("发货员：何庆华");
            Cell cell6 = row2.createCell(11);
            cell6.setCellStyle(style);
            cell6.setCellValue("审核:");
            /*if (cell == null) {
                cell = row.createCell(cellIndex); // 创建单元格
            }*/


               /* sheet.addMergedRegion(new CellRangeAddress(
                        iordersTemplates.size()+4, // first row (0-based)
                        iordersTemplates.size()+4, // last row  (0-based)
                        1, // first column (0-based)
                        4  // last column (0-based)
                ));
            sheet.addMergedRegion(new CellRangeAddress(
                    iordersTemplates.size()+4, // first row (0-based)
                    iordersTemplates.size()+4, // last row  (0-based)
                    4, // first column (0-based)
                    6  // last column (0-based)
            ));
            sheet.addMergedRegion(new CellRangeAddress(
                    iordersTemplates.size()+4, // first row (0-based)
                    iordersTemplates.size()+4, // last row  (0-based)
                    7, // first column (0-based)
                    9  // last column (0-based)
            ));
            sheet.addMergedRegion(new CellRangeAddress(
                    iordersTemplates.size()+4, // first row (0-based)
                    iordersTemplates.size()+4, // last row  (0-based)
                    11, // first column (0-based)
                    12  // last column (0-based)
            ));
*/


            workbook.write(fos); // 将更改写入文件
            fos.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


        /*response.setHeader("Content-Disposition", "attachment; filename=example.xlsx");
        try (OutputStream out = response.getOutputStream()) {
            workbook.write(out);
        }*/
        long total = PageInfo.of(iordersTemplates).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("fileLocation", outFilePath);
        data.put("items", iordersTemplates);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        logger.info("SDFSDFSDF");
        return ResponseUtil.ok(data)/*adminIorderService.delete(iordersTemplates)*/;

    }

    //生成分装清单
    @RequiresPermissions("admin:iorders:getSplitSheet2")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "生成分装清单")
    @PostMapping("/getSplitSheet2")
    public Object getSplitSheet2(/*@RequestBody List<IordersTemplate> iordersTemplates*/@RequestBody SplitListQuery splitListQuery) throws IOException {
       /* Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Data");*/
        String drawSample = splitListQuery.getDrawSample();
        String keepSample = splitListQuery.getKeepSample();
        /*logger.info(splitListQuery.get("tableData").toString());*/
        List<IordersTemplate> iordersTemplates1 = splitListQuery.getIordersTemplates();
        logger.info("抽样体积：" + drawSample + "  留样体积：" + keepSample);
        logger.info(iordersTemplates1.toString());

        IorderInfoAll infoAll = new IorderInfoAll();

        List<IorderInfoAll.InfoAll> infoAllList = new ArrayList<>();
        Integer totalCount = 0;
        Integer totalAc = 0;

        Double rowVolume = 0.00;
        Integer rowPiece = 0;
        String deliveryType = "";
        Double orderCount = 0.0;
        String batchNumber2 = "";
        Integer totalPieces = 0;
        Double totalVolume = 0.00;
        Integer concentration2 = 0;
        String productionDate2 = "";
        IorderInfoAll.InfoAll infos = null;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        DecimalFormat decimalFormat2 = new DecimalFormat("#0.0");
/*        Double keepSample1=Double.valueOf(decimalFormat.format(Double.valueOf(keepSample)));
        Double drawSample1=Double.valueOf(decimalFormat.format(Double.valueOf(drawSample)));*/
        List<IordersTemplate> iordersTemplates = iordersTemplates1;
        logger.info(iordersTemplates.getClass().toString());
        for (int i = 0; i < iordersTemplates.size(); i++) {
            IordersTemplate it = iordersTemplates.get(i);
            logger.info(it.getCustomerName());
        }
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {

                infos = new IorderInfoAll.InfoAll();
                /*Integer showId=it.getShowId();*/
                infos.setShowId(it.getShowId());
                infos.setUserName(it.getCustomerName());
                infos.setUseTime(it.getUseTime());
                /*totalCount=totalCount+it.getPieces();*/
                infos.setPieces(it.getPieces());

                totalPieces = totalPieces + it.getPieces();
                totalCount = totalCount + Integer.valueOf(it.getOrderCount());
                totalVolume = totalVolume + Double.valueOf(it.getSplitQuantity()) * it.getPieces();

                infos.setOrderCount(Integer.valueOf(it.getOrderCount()));
                infos.setDeliveryType(it.getDeliveryType());
                infos.setConcentration(Integer.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getOralConcentration()));
                infos.setBatchNumber(it.getMaterialBatch());
                concentration2 = infos.getConcentration();
                batchNumber2 = it.getMaterialBatch();
                infos.setConsegnee(it.getConsignee());
                infos.setConsegneePhone(it.getConsigneeTelephone());
                infos.setAddress(it.getAddress());
                infos.setProductName("碘[131I]化钠口服溶液");
                infos.setDateTime(LocalDate.now().toString());
                infos.setSplitDate(LocalDate.now().toString());

                infos.setMeasureTime(it.getMeasureTime());
                infos.setSpecs(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setOrderNumber(it.getOrderNum());
                infos.setOrderLineNumber(it.getOrderNum());
                infos.setType(IorderSpecial.getType(Integer.valueOf(it.getOrderCount())));
                infos.setPackageBase(decimalFormat.format(IorderSpecial.getPackIndex(Integer.parseInt(it.getOrderCount()), it.getDeliveryType(), Double.valueOf(it.getSplitQuantity()))));
                infos.setSplitBase(decimalFormat.format(Double.valueOf(it.getSplitQuantity()) / Double.valueOf(infos.getPackageBase())));
                infos.setSplitQuatity(Double.valueOf(it.getActualCount()));
                infos.setUnitPrice(ChineseMoneyConverter.getUnitPrice(Integer.valueOf(it.getOrderCount())));
                infos.setAllcac(Double.valueOf(it.getSplitQuantity()) * it.getPieces());  //总分装体积
                infos.setAvgCac(Double.valueOf(it.getSplitQuantity()));//平均每件分多少体积
                infos.setTotalPrice(ChineseMoneyConverter.CalculateMoney(Integer.valueOf(it.getOrderCount())));
                infos.setChineseYuan(new ChineseMoneyConverter2().format(infos.getTotalPrice().toString()));
                infos.setTotalCal(Double.valueOf(it.getSplitQuantity()) * it.getPieces());
                infos.setPackType(IorderSpecial.getPackType(it.getDeliveryType(), Integer.valueOf(it.getOrderCount())));
                infos.setConcentrationGbq(Double.valueOf(infos.getConcentration()) * 0.037 + "GBq");
                infos.setLabelCount(String.valueOf(decimalFormat2.format(Integer.valueOf(it.getOrderCount()) * 0.037)));
                infos.setPzwh(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setProductionDate(String.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getProductionDate()));
                infos.setOverdue(LocalDate.parse(infos.getProductionDate()).plusDays(24).toString());
                productionDate2 = infos.getProductionDate();
                rowPiece = rowPiece + 1;
                rowVolume = rowVolume + infos.getAllcac();
                infos.setActPack(String.valueOf(Math.round(infos.getSplitQuatity() * infos.getPieces())));
                infos.setPackMbq(String.valueOf(Integer.valueOf(infos.getActPack()) * 37));
                infoAllList.add(infos);
            }

        }
        rowPiece = rowPiece + 9;
        infoAll.setInfoAllList(infoAllList);
        infoAll.setTotalActivity(totalAc);
        infoAll.setTotalPiece(totalCount);
        infoAll.setTotalPieces(totalPieces);
        infoAll.setTotalVolume(totalVolume);
        infoAll.setBatchNumber2(batchNumber2);
        infoAll.setProductionDate2(productionDate2);
        infoAll.setConcentration2(concentration2);
        infoAll.setDateNow(LocalDate.now().toString());
        infoAll.setSplitDate2(LocalDate.now().toString());
        String templateFilePath = "D:/1--碘－131计算程序/模版/产品分装清单模板.xlsx";

        String outFilePath = "D:/1--碘－131计算程序/计算结果/中间件/" + "产品分装清单目标.xlsx";


        // 创建 ExcelWriter 实例
        ExcelWriter excelWriter = EasyExcel
                // 写入到
                .write(outFilePath)
                // 指定模板
                .withTemplate(templateFilePath)
                .build();

        WriteSheet sheet2 = EasyExcel.writerSheet().build();
        FillConfig fillConfig = FillConfig.builder()
                // 开启填充换行
                .forceNewRow(true)
                .build();
        // 执行填充操作
        excelWriter.fill(infoAll, fillConfig, sheet2);

        excelWriter.fill(infoAll.getInfoAllList(), fillConfig, sheet2);
        // 结束
        excelWriter.finish();
        String excelFilePath = outFilePath; // 替换为你的文件路径

        int sheetIndex = 0; // 工作表索引，从0开始
        int rowIndex = 1; // 行索引，从0开始
        int cellIndex = 0; // 单元格索引，从0开始
        String newValue = "新值"; // 要设置的新值
        String outFilePath1 = IorderSpecial.createSplitFile();
        String outputFilePath = outFilePath1; // 输出文件的路径
        try (FileInputStream fis = new FileInputStream(excelFilePath);
             Workbook workbook = new XSSFWorkbook(fis);
             FileOutputStream fos = new FileOutputStream(outFilePath1)) {
            XSSFFont font = (XSSFFont) workbook.createFont();
            font.setFontName("宋体");
            font.setFontHeightInPoints((short) 9); // 设置字体大小为12点

            // 创建单元格样式并应用字体
            XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle();
            style.setFont(font);
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setBorderTop(BorderStyle.THIN);
            style.setBorderBottom(BorderStyle.THIN);
            style.setBorderLeft(BorderStyle.THIN);
            style.setBorderRight(BorderStyle.THIN);
            Sheet sheet = workbook.getSheetAt(sheetIndex); // 获取工作表
            int startRow = iordersTemplates.size() + 7;
            int endRow = iordersTemplates.size() + 9;
            for (int n = 7; n <= 9 + iordersTemplates.size(); n++) {
                Row row = sheet.getRow(n);
                Cell cellN = row.createCell(14);
                cellN.setCellStyle(style);
                cellN.setCellValue("/"); // 设置单元格的值
            }

            for (int rowNum = startRow; rowNum <= endRow; rowNum++) {
                Row row = sheet.getRow(rowNum); // 创建行对象
                for (int j = 1; j < 14; j++) {
                    Cell cell = row.createCell(j); // 创建单元格对象
                    cell.setCellStyle(style);
                    cell.setCellValue("/"); // 设置单元格的值
                }

            }

            Row row1 = sheet.getRow(iordersTemplates.size() + 7);
            Row row2 = sheet.getRow(iordersTemplates.size() + 8); // 获取行，如果行不存在则返回null，需要创建行
            Row row3 = sheet.getRow(iordersTemplates.size() + 9);
            /* if (row == null) {
                row = sheet.createRow(rowIndex); // 创建行
            }*/
            Cell cell1 = row1.createCell(6); // 获取单元格，如果单元格不存在则返回null，需要创建单元格
            cell1.setCellStyle(style);
            Cell cell2 = row1.createCell(9);
            cell2.setCellStyle(style);
            Cell cell3 = row1.createCell(12);
            cell3.setCellStyle(style);
            Cell cell4 = row2.createCell(2);
            cell4.setCellStyle(style);
            Cell cell5 = row2.createCell(9);
            cell5.setCellStyle(style);
            Cell cell6 = row2.createCell(12);
            cell6.setCellStyle(style);
            /*if (cell == null) {
                cell = row.createCell(cellIndex); // 创建单元格
            }*/


            cell1.setCellValue(totalCount);
            cell2.setCellValue(totalVolume);
            cell3.setCellValue(totalPieces);

            if (drawSample.length() != 0) {
                cell4.setCellValue("成品抽样："); // 设置单元格的值
                cell5.setCellValue(drawSample);
                cell6.setCellValue(1);
            }
            if (keepSample.length() != 0) {
                Cell cell7 = row3.createCell(2);
                Cell cell8 = row3.createCell(9);
                cell8.setCellStyle(style);
                cell7.setCellStyle(style);
                Cell cell9 = row3.createCell(12);
                cell9.setCellStyle(style);
                cell7.setCellValue("成品留样："); // 设置单元格的值
                cell8.setCellValue(keepSample);
                cell9.setCellValue(1);
            }
            for (int n = 7; n <= 6 + iordersTemplates.size(); n++) {
                Row row = sheet.getRow(n);
                Cell cellN = row.getCell(2);
                Cell cellO = row.getCell(2);
                Cell cellP = row.getCell(2);
                cellN.setCellStyle(style);
                cellO.setCellStyle(style);
                cellP.setCellStyle(style);
                Cell cellM = row.getCell(14);
                cellM.setCellStyle(style);
            }
            for (int j = 8; j <= iordersTemplates.size() + 6; j++) {
                sheet.addMergedRegion(new CellRangeAddress(
                        j, // first row (0-based)
                        j, // last row  (0-based)
                        2, // first column (0-based)
                        4  // last column (0-based)
                ));
            }


            workbook.write(fos); // 将更改写入文件
            fos.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        long total = PageInfo.of(iordersTemplates).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("fileLocation", outFilePath);
        data.put("items", iordersTemplates);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        logger.info("SDFSDFSDF");
        return ResponseUtil.ok(data)/*adminIorderService.delete(iordersTemplates)*/;

    }


    //生产发运记录
    @RequiresPermissions("admin:iorders:getOAsheet")
    @RequiresPermissionsDesc(menu = {"碘131生产发货管理", "碘131分装"}, button = "生成导入OA表")
    @PostMapping("/getOAsheet")
    public Object getOAsheet(@RequestBody List<IordersTemplate> iordersTemplates) throws IOException {
       /* Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Data");*/
        IorderInfoAll infoAll = new IorderInfoAll();

        List<IorderInfoAll.InfoAll> infoAllList = new ArrayList<>();
        Integer totalCount = 0;
        Integer totalAc = 0;
        String deliveryType = "";
        Double orderCount = 0.0;
        IorderInfoAll.InfoAll infos = null;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        DecimalFormat decimalFormat2 = new DecimalFormat("#0.0");
        if (iordersTemplates != null) {
            for (IordersTemplate it : iordersTemplates) {

                infos = new IorderInfoAll.InfoAll();
                /*Integer showId=it.getShowId();*/
                infos.setShowId(it.getShowId());
                infos.setUserName(it.getCustomerName());
                infos.setUseTime(it.getUseTime());
                infos.setBase("放药产品仓库");
                totalCount = totalCount + it.getPieces();
                infos.setPieces(it.getPieces());
                totalAc = totalAc + Integer.valueOf(it.getOrderCount());
                infos.setOrderCount(Integer.valueOf(it.getOrderCount()));
                infos.setDeliveryType(it.getDeliveryType());
                infos.setConcentration(Integer.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getOralConcentration()));
                infos.setBatchNumber(it.getMaterialBatch());
                infos.setConsegnee(it.getConsignee());
                infos.setConsegneePhone(it.getConsigneeTelephone());
                infos.setAddress(it.getAddress());
                infos.setProductName("碘[131I]化钠口服溶液");
                infos.setDateTime(LocalDate.now().toString());
                infos.setSplitDate(LocalDate.now().toString());
                infos.setMeasureTime(it.getMeasureTime());
                infos.setSpecs(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setOrderNumber(it.getOrderNum());
                infos.setOrderLineNumber(it.getOrderNum());
                infos.setPackageBase(decimalFormat.format(IorderSpecial.getPackIndex(Integer.parseInt(it.getOrderCount()), it.getDeliveryType(), Double.valueOf(it.getSplitQuantity()))));
                infos.setSplitBase(decimalFormat.format(Double.valueOf(it.getSplitQuantity()) / Double.valueOf(infos.getPackageBase())));
                infos.setSplitQuatity(Double.valueOf(it.getActualCount()));
                infos.setUnitPrice(ChineseMoneyConverter.getUnitPrice(Integer.valueOf(it.getOrderCount())));
                infos.setAllcac(Double.valueOf(it.getSplitQuantity()) * it.getPieces());  //总分装体积
                infos.setAvgCac(Double.valueOf(it.getSplitQuantity()));//平均每件分多少体积
                infos.setTotalPrice(ChineseMoneyConverter.CalculateMoney(Integer.valueOf(it.getOrderCount())));
                infos.setChineseYuan(new ChineseMoneyConverter2().format(infos.getTotalPrice().toString()));
                infos.setTotalCal(Double.valueOf(it.getSplitQuantity()) * it.getPieces());
                infos.setPackType(IorderSpecial.getPackType(it.getDeliveryType(), Integer.valueOf(it.getOrderCount())));
                infos.setConcentrationGbq(Double.valueOf(infos.getConcentration()) * 0.037 + "GBq");

                infos.setLabelCount(String.valueOf(decimalFormat2.format(Integer.valueOf(it.getOrderCount()) * 0.037)));
                infos.setPzwh(IorderSpecial.getCF(Integer.valueOf(it.getOrderCount())));
                infos.setProductionDate(String.valueOf(productProductionService.queryByBatchNumber(it.getMaterialBatch()).getProductionDate()));
                infos.setOverdue(LocalDate.parse(infos.getProductionDate()).plusDays(24).toString());
                infos.setActPack(String.valueOf(Math.round(infos.getSplitQuatity() * infos.getPieces())));
                infos.setPackMbq(String.valueOf(Integer.valueOf(infos.getActPack()) * 37));
                infoAllList.add(infos);
            }

        }
        infoAll.setInfoAllList(infoAllList);
        infoAll.setTotalActivity(totalAc);
        infoAll.setTotalPiece(totalCount);
        infoAll.setDateNow(LocalDate.now().toString());
        String templateFilePath = "D:/1--碘－131计算程序/模版/生产数据导入模板（碘数据） .xlsx";
        String outFilePath = "D:/1--碘－131计算程序/计算结果/生产数据导入模板（碘） .xlsX";
        // 创建 ExcelWriter 实例
        ExcelWriter excelWriter = EasyExcel
                // 写入到
                .write(outFilePath)
                // 指定模板
                .withTemplate(templateFilePath)
                .build();

        WriteSheet sheet2 = EasyExcel.writerSheet().build();
        FillConfig fillConfig = FillConfig.builder()
                // 开启填充换行
                .forceNewRow(true)
                .build();
        // 执行填充操作
        excelWriter.fill(infoAll, fillConfig, sheet2);

        excelWriter.fill(infoAll.getInfoAllList(), fillConfig, sheet2);
        // 结束
        excelWriter.finish();

        /*response.setHeader("Content-Disposition", "attachment; filename=example.xlsx");
        try (OutputStream out = response.getOutputStream()) {
            workbook.write(out);
        }*/
        long total = PageInfo.of(iordersTemplates).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("fileLocation", outFilePath);
        data.put("items", iordersTemplates);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        logger.info("SDFSDFSDF");
        return ResponseUtil.ok(data)/*adminIorderService.delete(iordersTemplates)*/;

    }

    @PostMapping("/getEditInfo1") //根据订量变化计算分装体积变化
    public Object getEditInfos1(@RequestBody EditPageQuery1 editPageQuery) {
        logger.info("根据订量变化计算分装体积变化");
        String batchNumber = editPageQuery.getBatchNumber();
        String userName = editPageQuery.getUserName();
        String useTime = editPageQuery.getUseTime();
        Integer pieces = editPageQuery.getPieces();
        Integer orderCount =editPageQuery.getOrderCount();
        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        LocalDateTime measureTine = production.getMeasureTine();
        Integer concentration = production.getOralConcentration();
        Integer newPiece=0;
        String  newActualCount="";
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        /*String splitQuantity1 =decimalFormat.format(editPageQuery.getSpitQuantity());*/

        double constantNum = -0.0864089775561;

        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(measureTine, LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        //先判断分多少件
         String newSplitQuantity="";
        Double newSplitQuantity1=orderCount / result * IorderSpecial.getResult(userName);
        if (Double.valueOf(newSplitQuantity1) > 10) {
            newPiece = Integer.valueOf((int) (Double.valueOf(newSplitQuantity1) / 10)) + 1;
            newSplitQuantity = String.valueOf(decimalFormat.format(newSplitQuantity1 / newPiece));
        }else{
            newSplitQuantity=String.valueOf(decimalFormat.format(newSplitQuantity1));
            newPiece=1;
        }
        String newActualCount1="";
        newActualCount1=decimalFormat.format(newSplitQuantity1 * concentration / newPiece);
        newActualCount=String.valueOf(Math.round(Double.valueOf(newActualCount1)));

        Map<String, Object> data = new HashMap<>();
        data.put("splitQuantity", newSplitQuantity);
        data.put("actualCount", newActualCount);
        data.put("pieces",newPiece);
        return ResponseUtil.ok(data);
        /*double constantNum = -0.0864089775561;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        String splitQuantity = String.valueOf(decimalFormat.format(orderCount / result * IorderSpecial.getResult(userName)));
        Integer newPiece = 0;
        Double newSplitQuantity = 0.00;
        if (Double.valueOf(splitQuantity) > 10) {
            newPiece = Integer.valueOf((int) (Double.valueOf(splitQuantity) / 10)) + 1;
            newSplitQuantity = Double.valueOf(splitQuantity) / newPiece;


        } else {
            newSplitQuantity = Double.valueOf(splitQuantity);
        }
        String xxx = decimalFormat.format(Double.valueOf(splitQuantity) * concentration);
        Integer acturalCount = Integer.parseInt(xxx.substring(0, xxx.indexOf('.')));
        Map<String, Object> data = new HashMap<>();
        data.put("splitQuantity", newSplitQuantity);
        data.put("acturalCount", acturalCount);
        data.put("pieces", newPiece);

        return ResponseUtil.ok(data);*/


    }

    @PostMapping("/getEditInfo2") //根据分装体积变化计算订量变化
    public Object getEditInfos2(@RequestBody EditPageQuery2 editPageQuery) {

        String batchNumber = editPageQuery.getBatchNumber();
        String userName = editPageQuery.getUserName();
        String useTime = editPageQuery.getUseTime();
        Double splitQuantity=editPageQuery.getSplitQuantity();
        Integer pieces = editPageQuery.getPieces();

        String newOrderCount="";
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        /*String splitQuantity1 =decimalFormat.format(editPageQuery.getSpitQuantity());*/

        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        LocalDateTime measureTine = production.getMeasureTine();
        Integer concentration = production.getOralConcentration();
        double constantNum = -0.0864089775561;

        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(measureTine, LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        //先判断分多少件
        String newActualCount=String.valueOf(Math.round(splitQuantity * concentration));
        splitQuantity=splitQuantity/IorderSpecial.getResult(userName);

         newOrderCount=String.valueOf(Math.round(splitQuantity * result * pieces));
        Map<String, Object> data = new HashMap<>();
        data.put("orderCount", newOrderCount);
        data.put("actualCount",newActualCount);
        return ResponseUtil.ok(data);
        /*if (pieces == null) {
            pieces = 1;
        }

        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        *//*String splitQuantity1 =decimalFormat.format(editPageQuery.getSpitQuantity());*//*
        Double splitQuantity = editPageQuery.getSplitQuantity();
        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        LocalDateTime measureTine = production.getMeasureTine();
        Integer concentration = production.getOralConcentration();
        double constantNum = -0.0864089775561;

        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        //先判断分多少件
        if (pieces > 0 && pieces != null) {
            String yyy = decimalFormat.format(splitQuantity * result * pieces / IorderSpecial.getResult(userName));
            Integer orderCount = Integer.parseInt(yyy.substring(0, yyy.indexOf('.')));

            String zzz = decimalFormat.format(splitQuantity * concentration * pieces);
            Integer acturalCount = Integer.parseInt(zzz.substring(0, zzz.indexOf('.')));
            Map<String, Object> data = new HashMap<>();
            data.put("orderCount", orderCount);

            data.put("acturalCount", acturalCount);
            return ResponseUtil.ok(data);
        } else {
            return ResponseUtil.badArgument();
        }*/
    }

    @PostMapping("/getEditInfo3") //根据用户名变化计算分装体积变化
    public Object getEditInfos3(@RequestBody EditPageQuery1 editPageQuery) {

        String userName=editPageQuery.getUserName();


       Integer orderCount=editPageQuery.getOrderCount();


        String batchNumber = editPageQuery.getBatchNumber();

        String useTime = editPageQuery.getUseTime();
        Integer pieces = editPageQuery.getPieces();

        Integer newPiece=0;
        String newActualCount="";
        Double newSplitQuantity=0.00;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");

        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        LocalDateTime measureTine = production.getMeasureTine();
        Integer concentration = production.getOralConcentration();
        double constantNum = -0.0864089775561;

        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        //先判断分多少件
        double totalSplitCount=(orderCount / result) * IorderSpecial.getResult(userName);
        if (totalSplitCount > 10) {
            newPiece = Integer.valueOf((int) (totalSplitCount / 10)) + 1;
            newSplitQuantity = Double.valueOf(decimalFormat.format(totalSplitCount / newPiece));
        }else{
            newPiece=1;
            newSplitQuantity=Double.valueOf(decimalFormat.format(totalSplitCount));
        }
        newActualCount=String.valueOf(Math.round(totalSplitCount * concentration / newPiece));


            Map<String, Object> data = new HashMap<>();
        data.put("splitQuantity", newSplitQuantity);
        data.put("pieces",newPiece);
        data.put("actualCount", newActualCount);
        return ResponseUtil.ok(data);
    }
   /* @PostMapping("/getEditInfo4") //根据件数变化计算分装体积变化
    public Object getEditInfos4(@RequestBody EditPageQuery1 editPageQuery) {

        String batchNumber = editPageQuery.getBatchNumber();
        String userName = editPageQuery.getUserName();
        String useTime = editPageQuery.getUseTime();
        Integer pieces = editPageQuery.getPieces();
        Integer orderCount=editPageQuery.getOrderCount();
        Integer actualCount=editPageQuery.getActualCount();
        Integer newOrderCount= Integer.valueOf(orderCount) * pieces;
        Integer newActualCount=0;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        *//*String splitQuantity1 =decimalFormat.format(editPageQuery.getSpitQuantity());*//*

        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        LocalDateTime measureTine = production.getMeasureTine();
        Integer concentration = production.getOralConcentration();
        double constantNum = -0.0864089775561;

        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        //先判断分多少件
        Double newSplitQuantity=Double.valueOf(decimalFormat.format(orderCount / result)) * IorderSpecial.getResult(userName);
        if (Double.valueOf(newSplitQuantity) > 10) {
            newPiece = Integer.valueOf((int) (Double.valueOf(newSplitQuantity) / 10)) + 1;
            newSplitQuantity = Double.valueOf(decimalFormat.format(newSplitQuantity / newPiece));
        }else{
            newSplitQuantity=newSplitQuantity;
        }
        newActualCount=Integer.valueOf(decimalFormat.format(newSplitQuantity * result));


        Map<String, Object> data = new HashMap<>();
        data.put("orderCount", newOrderCount);

        return ResponseUtil.ok(data);

    }*/
   @PostMapping("/getEditInfo4") //根据使用时间变化计算分装体积及实际装量变化
   public Object getEditInfos4(@RequestBody EditPageQuery1 editPageQuery) {
       logger.info("根据订量变化计算分装体积变化");
       String batchNumber = editPageQuery.getBatchNumber();
       String userName = editPageQuery.getUserName();
       String useTime = editPageQuery.getUseTime();
       Integer pieces = editPageQuery.getPieces();
       Integer orderCount = Integer.valueOf(editPageQuery.getOrderCount());
       ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
       LocalDateTime measureTine = production.getMeasureTine();
       Integer concentration = production.getOralConcentration();
       Integer newPiece=0;
       Integer newActualCount=0;
       DecimalFormat decimalFormat = new DecimalFormat("#0.00");
       /*String splitQuantity1 =decimalFormat.format(editPageQuery.getSpitQuantity());*/

       double constantNum = -0.0864089775561;

       double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(measureTine, LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
       //先判断分多少件
       String newSplitQuantity="";
       Double newSplitQuantity1=Double.valueOf(decimalFormat.format(orderCount / result)) * IorderSpecial.getResult(userName);
       if (Double.valueOf(newSplitQuantity1) > 10) {
           newPiece = Integer.valueOf((int) (newSplitQuantity1 / 10)) + 1;
           newSplitQuantity = decimalFormat.format(newSplitQuantity1 / newPiece);
       }else{
           newPiece=1;
           newSplitQuantity=decimalFormat.format(newSplitQuantity1);
       }
       String ss=String.valueOf(Math.round(newSplitQuantity1 * concentration));
       newActualCount=Integer.valueOf(ss);


       Map<String, Object> data = new HashMap<>();
       data.put("splitQuantity", newSplitQuantity);
       data.put("actualCount", newActualCount);
       data.put("pieces",newPiece);
       return ResponseUtil.ok(data);
        /*double constantNum = -0.0864089775561;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        String splitQuantity = String.valueOf(decimalFormat.format(orderCount / result * IorderSpecial.getResult(userName)));
        Integer newPiece = 0;
        Double newSplitQuantity = 0.00;
        if (Double.valueOf(splitQuantity) > 10) {
            newPiece = Integer.valueOf((int) (Double.valueOf(splitQuantity) / 10)) + 1;
            newSplitQuantity = Double.valueOf(splitQuantity) / newPiece;


        } else {
            newSplitQuantity = Double.valueOf(splitQuantity);
        }
        String xxx = decimalFormat.format(Double.valueOf(splitQuantity) * concentration);
        Integer acturalCount = Integer.parseInt(xxx.substring(0, xxx.indexOf('.')));
        Map<String, Object> data = new HashMap<>();
        data.put("splitQuantity", newSplitQuantity);
        data.put("acturalCount", acturalCount);
        data.put("pieces", newPiece);

        return ResponseUtil.ok(data);*/


   }
    @PostMapping("/getEditInfo5") //根据件数变化计算分装体积变化
    public Object getEditInfos5(@RequestBody EditPageQuery1 editPageQuery) {
        logger.info("根据件数变化计算分装体积变化");
        String batchNumber = editPageQuery.getBatchNumber();
        String userName = editPageQuery.getUserName();
        String useTime = editPageQuery.getUseTime();
        Integer pieces = editPageQuery.getPieces();
        Integer orderCount =editPageQuery.getOrderCount();
        ProductProduction production = productProductionService.queryByBatchNumber(batchNumber);
        LocalDateTime measureTine = production.getMeasureTine();
        Integer concentration = production.getOralConcentration();
        Integer newPiece=0;
        Integer newActualCount=0;
        Integer newOrderCount=0;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        /*String splitQuantity1 =decimalFormat.format(editPageQuery.getSpitQuantity());*/

        double constantNum = -0.0864089775561;

        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(measureTine, LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        //先判断分多少件

        Double newSplitQuantity=Double.valueOf(decimalFormat.format(orderCount / result)) * IorderSpecial.getResult(userName);

        String ss=decimalFormat.format(newSplitQuantity * result / pieces);
        newActualCount=Integer.valueOf(ss.substring(0,ss.indexOf(".")));
        newOrderCount=newActualCount * pieces;

        Map<String, Object> data = new HashMap<>();

        data.put("orderCount", newOrderCount);
        return ResponseUtil.ok(data);
        /*double constantNum = -0.0864089775561;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        double result = concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), LocalDate.parse(useTime.substring(0, 10)).atTime(12, 0)) + 1));
        String splitQuantity = String.valueOf(decimalFormat.format(orderCount / result * IorderSpecial.getResult(userName)));
        Integer newPiece = 0;
        Double newSplitQuantity = 0.00;
        if (Double.valueOf(splitQuantity) > 10) {
            newPiece = Integer.valueOf((int) (Double.valueOf(splitQuantity) / 10)) + 1;
            newSplitQuantity = Double.valueOf(splitQuantity) / newPiece;


        } else {
            newSplitQuantity = Double.valueOf(splitQuantity);
        }
        String xxx = decimalFormat.format(Double.valueOf(splitQuantity) * concentration);
        Integer acturalCount = Integer.parseInt(xxx.substring(0, xxx.indexOf('.')));
        Map<String, Object> data = new HashMap<>();
        data.put("splitQuantity", newSplitQuantity);
        data.put("acturalCount", acturalCount);
        data.put("pieces", newPiece);

        return ResponseUtil.ok(data);*/


    }

}